/*
 * @lc app=leetcode.cn id=303 lang=cpp
 *
 * [303] 区域和检索 - 数组不可变
 */

// @lc code=start
class NumArray {
private:
    vector<int> _nums;
public:
    NumArray(vector<int>& nums) {
        int Sum = 0;
        for(int i = 0; i < nums.size() ; i++)
        {
            Sum += nums[i];
            _nums.push_back(Sum);
        }
    }
    
    // int sumRange(int i, int j) {
    //     int Sum = 0;
    //     for(int k = i;k<=j;k++)
    //     {
    //         Sum += _nums[k];
    //     }
    //     return Sum;

    // }
    int sumRange(int i, int j) {
        if(i == 0)
        {
            return _nums[j];
        }
        else
        {
            return _nums[j]-_nums[i -1];
        }
    }
};

/**
 * Your NumArray object will be instantiated and called as such:
 * NumArray* obj = new NumArray(nums);
 * int param_1 = obj->sumRange(i,j);
 */
// @lc code=end

